﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using JoyTalq.Core.Business;
using JoyTalq.Core.Business.Service;
using JoyTalq.Core.Business.Domain;

namespace JoyTalq.Core.Business.Test.Service
{
    [TestFixture]
    public class TestBusinessService
    {
        public BusinessFactory BusinessFactory { get; set; }
        public IBusinessService BusinessService { get; set; }

        [TestFixtureSetUp]
        public void TestCaseInit()
        {
            BusinessFactory = new BusinessFactory();
            BusinessService = BusinessFactory.GetBusinessService();
        }

        [Test]
        public void Test_CreateCustomer()
        {
            Console.WriteLine("start = " + DateTime.Now);
            for (int i = 0; i < 20000; i++)
            {
                CustomerVO customerVO = new CustomerVO();
                customerVO.NameZh = "a" + i;
                customerVO.NameEn = "b" + i;
                customerVO.CreateTime = DateTime.Now;
                customerVO.UpdateTime = DateTime.Now;
                BusinessService.CreateCustomer(customerVO);
            }
            Console.WriteLine("end = " + DateTime.Now);
        }

        [Test]
        public void Test_CreateCustomer_And_Brand()
        {
            Console.WriteLine("start = " + DateTime.Now);
            for (int i = 0; i < 1; i++)
            {
                CustomerVO customerVO = new CustomerVO();
                customerVO.NameZh = "a" + i;
                customerVO.NameEn = "b" + i;
                customerVO.CreateTime = DateTime.Now;
                customerVO.UpdateTime = DateTime.Now;
                customerVO = BusinessService.CreateCustomer(customerVO);

                for (int j = 0; j < 5; j++)
                {
                    BrandVO brandVO = new BrandVO();
                    brandVO.Customer = customerVO;
                    brandVO.NameZh = customerVO.NameZh + "a" + j;
                    brandVO.NameEn = customerVO.NameEn + "b" + j;
                    brandVO.CreateTime = DateTime.Now;
                    brandVO.UpdateTime = DateTime.Now;
                    BusinessService.CreateBrand(brandVO);

                    //BrandVO brandVO2 = BusinessService.GetBrandById(brandVO.BrandId);
                    //Console.WriteLine("CustomerId = " + brandVO2.Customer.CustomerId);
                    //Console.WriteLine("CustomerNameZh = " + brandVO2.Customer.NameZh);
                }
            }
            Console.WriteLine("end = " + DateTime.Now);
        }

        [Test]
        public void Test_GetAllCustomerList()
        {
            Console.WriteLine("start = " + DateTime.Now);
            IList<CustomerVO> customerList = BusinessService.GetAllCustomerList(0, 10, "CustomerId", true);
            Console.WriteLine("end = " + DateTime.Now);
            Console.WriteLine("count = " + customerList.Count());
            //foreach (CustomerVO customerVO in customerList)
            //{
            //    Console.WriteLine("countBrand1 = " + customerVO.BrandList.Count());
            //}

            Console.WriteLine("start = " + DateTime.Now);
            IList<CustomerVO> customerList2 = BusinessService.GetAllCustomerList();
            Console.WriteLine("end = " + DateTime.Now);
            Console.WriteLine("count = " + customerList2.Count());
            //foreach (CustomerVO customerVO in customerList2)
            //{
            //    Console.WriteLine("countBrand2 = " + customerVO.BrandList.Count());
            //}
        }
    }
}
